/*
 * DMouseEvent.h
 *
 *  Created on: 2010-9-5
 *      Author: try
 */

#ifndef MOUSEEVENT_H_
#define MOUSEEVENT_H_

#include "../commons.h"
#include "ddatatypes.h"
#include "KeySequence.h"
#include <event/Event.h>

namespace Ed {

  class MouseEvent: public Thk::Event {
    public:
      /**
       * x, y 为鼠标在终端窗口区坐标
       */
      MouseEvent(EventType type, int x, int y, MouseButton button, void* source=NULL);
      MouseEvent(EventType type, int x, int y, unsigned int buttons, void* source=NULL);
      MouseEvent(EventType type, void* source=NULL);

      MouseEvent(EventType type, int x, int y, MouseButton button, int key, void* source=NULL);
      MouseEvent(EventType type, int x, int y, unsigned int buttons, int key, void* source=NULL);
      MouseEvent(EventType type, int key, void* source=NULL);

      MouseEvent(EventType type, int x, int y, MouseButton button, const KeySequence& ks, void* source=NULL);
      MouseEvent(EventType type, int x, int y, unsigned int buttons, const KeySequence& ks, void* source=NULL);
      MouseEvent(EventType type, const KeySequence& ks, void* source=NULL);

      MouseEvent(const MouseEvent& me);
      MouseEvent(const MouseEvent* me);

      virtual ~MouseEvent();

      /**
       * 检查按钮状态
       */
      inline bool pressed(MouseButton button) const{
        return buttons & button;
      }

      /**
       * 返回按键信息
       */
      inline unsigned int getButtons() const{
        return buttons;
      }

      inline const KeySequence& getKeySequence() const{
        return keySequence;
      }

      inline int x() const {
        return _x;
      }

      inline int y() const {
        return _y;
      }

      inline void setX(int x){
        _x = x;
      }

      inline void setY(int y){
        _y = y;
      }

//      inline int layerX() const {
//        return _lx;
//      }
//
//      inline int layerY() const {
//        return _ly;
//      }
//
//      inline void setLayerX(int x){
//        _lx = x;
//      }
//
//      inline void setLayerY(int y){
//        _ly = y;
//      }
//
//      inline int pageX() const {
//        return _px;
//      }
//
//      inline int pageY() const {
//        return _py;
//      }
//
//      inline void setPageX(int x){
//        _px = x;
//      }
//
//      inline void setPageY(int y){
//        _py = y;
//      }

      inline void setPageEvent(const MouseEvent* me){
        pageEvent = me;
      }

      inline const MouseEvent* getPageEvent() const{
        return pageEvent;
      }

      inline void setLayerEvent(const MouseEvent* me){
        layerEvent = me;
      }

      inline const MouseEvent* getLayerEvent() const{
        return layerEvent;
      }

      /**
       * 检查是否鼠标事件
       */
      static inline bool isMouseEvent(EventType type){
        return type>MinType && type<MaxType;
      }

      /**
       * 检查是否鼠标事件
       */
      static inline bool isMouseEvent(const Event* e){
        EventType type = e->getType();
        return type>MinType && type<MaxType;
      }

      //类型范围
      static EventType MinType;
      static EventType MaxType;

      //所有鼠标相关事件类型
      static EventType MoveType;
      static EventType LeaveType;
      static EventType EnterType;
      static EventType PressType;
      static EventType ReleaseType;
      static EventType DoubleClickType;

    protected:
      int _x, _y; //当前层或当前元素上的坐标
//      int _lx, _ly; //在层上的坐标
//      int _px, _py; //在画布上的坐标
      unsigned int buttons;
      KeySequence keySequence;
      //在画布上的鼠标事件
      const MouseEvent* pageEvent;
      //在层上的鼠标事件
      const MouseEvent* layerEvent;
  };

}

#endif /* MOUSEEVENT_H_ */
